import Vue from 'vue'
import VueRouter from 'vue-router'
// import dataCache from '@/utils/dataCache.js'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/main'
  },
  {
    path: '/register',
    name: 'register',
    component: () => import('../views/register/register.vue')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/login/login.vue')
  },
  {
    path: '/main',
    name: 'main',
    component: () => import('../views/main/main.vue'),
    children: [
      {
        path: '/user',
        name: 'user',
        component: () => import('../views/main/user/user.vue')
      },
      {
        path: '/article',
        name: 'article',
        component: () => import('../views/main/article/article.vue')
      },
      {
        path: '/mall',
        name: 'mall',
        component: () => import('../views/main/mall/mall.vue')
      }
    ]
  },
  {
    path: '/:pathMatch(.*)*',
    name: 'not-found',
    component: () => import('../views/not-found/not-found.vue')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

// router.beforeEach((to) => {
//   if (to.path !== '/login') {
//     const token = dataCache.getCache('token')
//     if (!token) {
//       return '/login'
//     }
//   }
//   if (to.path === '/main') {
//     return firstMenu.path
//   }
// })

export default router
